<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of InscriptionForm
 *
 * @author AHAMADA
 */
class InscriptionForm extends BaseForm{
    
    public function configure()
    {

      $this->setWidgets(array(
      'username' => new sfWidgetFormInputText(),
      'last_name' => new sfWidgetFormInputText(),
      'first_name' => new sfWidgetFormInputText(),
      'email_address'   => new sfWidgetFormInputText(),
      'password' => new sfWidgetFormInputPassword(),
      'password2' => new sfWidgetFormInputPassword(),
      'zipcode' => new sfWidgetFormInputText(),
      'city' => new sfWidgetFormInputText()          
    ));
    
    $choices = array('M' => 'Mr' ,'F'=> 'Mme', 'D' => 'Mlle');
    $this->widgetSchema['gender'] = new sfWidgetFormChoice(array(
    'choices'  => $choices,
    'expanded' => true,
));  

    $years = range(1922, 1994);
    $this->widgetSchema['birthdaydate'] = new sfWidgetFormDate(
             array('years' => array_combine($years, $years),
                   'format' => '%day% - %month% - %year%'
                  )); 

          
    $this->setValidators(array(
      'username'  => new sfValidatorString(array('required' => true,'max_length'=> 10), array('required' => '')),
      'last_name'    => new sfValidatorString(array('required' => true,'max_length' => 50),array('required' => ' ')),
      'first_name'   => new sfValidatorString(array('required' => true, 'max_length' => 50),array('required' => ' ')),
      'email_address' => new sfValidatorEmail(array('max_length' => 255), array('invalid' => 'email est invalide.','required' => ' ')),
      'password' =>  new sfValidatorString(array('required' => true),array('required' => ' ')),
      'password2' =>  new sfValidatorString(array('required' => true),array('required' => ' ')),
      'gender' =>  new sfValidatorString(array('required' => true),array('required' => ' ')),
      'zipcode' =>  new sfValidatorString(array('required' => true,'max_length' => 5),array('required' => '      ','max_length' => '"%value%" est trop long' )),
      'city' =>  new sfValidatorString(array('required' => true,'max_length' => 128),array('required' => ' ')),
      'birthdaydate' => new sfValidatorDate(array('with_time' => false),array('required' => ' '))
        ));
    

      $this->mergePostValidator(
                                new sfValidatorSchemaCompare(
                                        'password', sfValidatorSchemaCompare::EQUAL, 
                                        'password2',array(),
                                    array( 'invalid' => 'mot de passe non identique' )
                                     )
                                );
      
      
      $this->mergePostValidator(
  
                                new sfValidatorDoctrineUnique(
                                    array(
                                        'required'=> true, 
                                        'model' => 'sfGuardUser', 
                                        'column' => array('email_address')), 
                                    array(
                                        'invalid' => 'user existe')
                                   )
           );
      $this->mergePostValidator(
  
                                new sfValidatorDoctrineUnique(
                                    array(
                                        'required'=> true, 
                                        'model' => 'sfGuardUser', 
                                        'column' => array('username')), 
                                    array(
                                        'invalid' => 'user existe')
                                   )
           );
      $this->widgetSchema->setNameFormat('signup[%s]');
      
      
    }
}

?>
